<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['ischecklogin']=model('jy_weishop/member')->checklogin('','','','',true);
$worker = pdo_get('jy_weishop_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'yuejie_type'=>array(1,2)));
if(empty($worker)){
	exi('您不是月结客户！','error','/apply/');
}
$basic=model('core/member')->basic($_SESSION['uid']);
$worker=array_merge($basic,$worker);
if($_RQ['op']=='main'){
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	if($worker['yuejie_type']==1){
		$mids=$this->model('model')->getworkermids($_SESSION['uid']);
		$jielog=$this->model('model')->up_lastmonth($worker);
	}else{
		$mids=$_SESSION['uid'];
	}
	$yuejiemid=model('jy_yuejie/model')->checktype();
	$worker['today_money']=pdo_getsum('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mids,'yuejiemid'=>$yuejiemid,'ispay'=>1,'createtime >'=>$daytime),'price');
	$worker['today_num']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mids,'yuejiemid'=>$yuejiemid,'ispay'=>1,'createtime >'=>$daytime));
	$worker['all_money']=pdo_getsum('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mids,'yuejiemid'=>$yuejiemid,'ispay'=>1),'price');
	$worker['all_num']=pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mids,'yuejiemid'=>$yuejiemid,'ispay'=>1));
	$worker['yuejie_endtime']=$worker['yuejie_endtime']?date('Y-m-d',$worker['yuejie_endtime']):'永久';
	$worker['url']=custom_url('jy_yuejie/sao//fromuser='.$_SESSION['uid'],true);
	$worker['wurl']=custom_url('jy_yuejie/wsao//adminmid='.$_SESSION['uid'],true);
	if($_SESSION['wxapp_id']){
		$image='oss/'.$_SESSION['uniacid'].'/images/jy_yuejie/wxappid'.$_SESSION['wxapp_id'].'_'.$_SESSION['uid'].'.jpg';
		$isadd=cfc('files')->source_check($image);
		if(!$isadd){
			$url='/jy_yuejie/sao/index?fromuser='.$_SESSION['uid'];
			$wxapp=pdo_get('core_account_wxapp',array('id'=>$_SESSION['wxapp_id'],'uniacid'=>$_SESSION['uniacid']));
			if($_SESSION['fromh5wxapp']){
				$url='jy_yuejie/sao//fromuser='.$_SESSION['uid'];
				$url='/pages/index/index?url='.urlencode($url);
			}
			$res=model('core/wxapp')->appcode($url,$wxapp['appid'],$wxapp['appsecret'],200);
			$path='oss/'.$_SESSION['uniacid'].'/images/jy_yuejie';
			if(!file_exists(ROOT_AT.$path)){
				mkdir(ROOT_AT.$path,0700, true);
			}
			cfc('files')->source_save($res,'nochoose','png','二维码',$image,'',$url);
		}
		$return['appcode']=$image;
	}
	$return['worker']=$worker;
	$return['jielog']=$jielog;	
	set_html('title','月结中心');
	exi($return);
}
if($_RQ['op']=='set'){
	if($_RQ['postdata']){
		$postdata=get_postdata();	
		$data=array(
				'headimg'=>$postdata['headimg'],
				'title'=>$postdata['title'],
				'address'=>$postdata['address'],
				'mobile'=>$postdata['mobile'],
		);
		$worker_id=pdo_getcolumn('jy_weishop_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'id');		
		if($worker_id){
			pdo_update('jy_weishop_member',$data,array('id'=>$worker_id));
			exi('修改成功','','main');		 
		}
	}
	$worker=pdo_get('jy_weishop_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$return['worker']=$worker;
	exi($return);
}
?>